from django import forms
from detect.models import UserImage
from django import forms

from django.utils.datastructures import MultiValueDict

class MultiFileInput(forms.ClearableFileInput):
    allow_multiple_selected = True

    def value_from_datadict(self, data, files, name):
        if isinstance(files, MultiValueDict):
            return files.getlist(name)
        elif isinstance(files, dict) and name in files:
            # 如果不是 MultiValueDict，就变成单个文件列表返回
            return [files[name]]
        return []


class uploadForm(forms.ModelForm):
    Images = forms.ImageField(label="多图片上传",widget=forms.ClearableFileInput())
    UserId = forms.IntegerField(label="用户id",widget=forms.TextInput())
    class Meta:
        model = UserImage
        fields = '__all__'